import argparse
import os.path

from net.socket_server import SocketServer

parser = argparse.ArgumentParser(description="Edge Server listener")
parser.add_argument("--listen_host", type=str, default='0.0.0.0', help='Listen host')
parser.add_argument("--listen_port", type=int, default=12345, help='Listen port')
args = parser.parse_args()

def check_and_create_directory(directory):
    # 检查目录是否存在
    if not os.path.exists(directory):
        # 如果目录不存在，则创建它
        os.makedirs(directory)
        print(f"Directory {directory} created.")
    else:
        print(f"Directory {directory} already exists.")

if __name__ == '__main__':

    user_home_directory = os.path.expanduser("~")
    target_directory = os.path.join(user_home_directory, ".fedchain", "pre_datas")
    model_directory = os.path.join(user_home_directory, ".fedchain", "model")
    check_and_create_directory(target_directory)
    check_and_create_directory(model_directory)

    server = SocketServer(args.listen_host, args.listen_port, target_directory, model_directory)
    server.start_server()